import { QXEvent } from 'qx-util';
import {
	IParam,
	EditFormActionType,
	IEditFormAbility,
	IEditFormControllerParams,
	IEditFormStore,
	EditFormController,
	ICtrlEvent,
	IEditFormController,
	IEditFormModel,
} from '@/core';
import {
	useFormAction,
	useFormBasic,
	useFormControllerParams,
	useFormProps,
} from '@/hooks/widget/use-form';
import { FormControlVO } from './main-form-vo';
import { model } from './main-form-model';
import FormService from '@/core/modules/ctrl-service/form-service';
// 基于template/src/widgets/{{appEntities}}/{{ctrls@FORM}}-form/{{spinalCase ctrl.codeName}}-form-hook.ts.hbs生成
/**
 * 获取输入参数
 *
 * @export
 * @return {*}
 */
export function useProps() {
	return {
		...useFormProps(),
	};
}

/**
 * 获取基础数据
 *
 * @export
 * @param {*} props
 * @return {*}
 */
export function useBasic(props: any) {
	return {
		...useFormBasic(model, props),
	};
}

/**
 * 获取行为
 *
 * @export
 */
export function useAction(controller: any) {
	return {
		...useFormAction(controller),
	};
}

/**
 * 获取控制器
 *
 * @export
 * @param {IParam} props
 * @param {QXEvent<ICtrlEvent<EditFormActionType, IEditFormAbility>>} evt
 * @return {*}
 */
export function useController(
	props: IParam,
	evt: QXEvent<ICtrlEvent<EditFormActionType, IEditFormAbility>>,
	otherParams: IParam = {}
): IEditFormController<IEditFormStore, IEditFormAbility> {
	const params: IEditFormControllerParams<
		EditFormActionType,
		IEditFormAbility
	> = useFormControllerParams<IEditFormStore, IEditFormModel>(
		model,
		props,
		evt,
		otherParams
	);
	const ctrlService = new FormService<FormControlVO>(
		FormControlVO,
		model.entityCodeName
	);
	Object.assign(params, { ctrlService });
	return new EditFormController(params);
}
